package com.apes.framework.plugin.form.parser.element;

import com.apes.framework.plugin.form.parser.node.FormNodeParser;
import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.filereader.xml.ApesElementParser;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 功能：subtotal
 *
 * @author xul
 * @create 2018-06-06 17:48
 */
@Component
public class SubtotalElementParser implements ApesElementParser<ApesElement, List> {

    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"subtotal"};

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return FormNodeParser.domain;
    }

    /**
     * 功能：可解析的元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }


    @Override
    public List parse(ApesElement element) {
        return element.getNestedElements().stream()
                .map(new Function<ApesElement, Object>() {
                    @Override
                    public Object apply(ApesElement apesElement) {
                        return apesElement.parse();
                    }
                }).collect(Collectors.toList());
    }

}
